﻿// <copyright file="Password.cs" company="BerlinSoft">
// Copyright (c) 2009 All Right Reserved
// </copyright>
// <author>Wernfried Schwenkner</author>
// <email>wernfried@schwenkner.de</email>
// <date>2009-10-21</date>
// <summary>
// Contains the class of Password.
// </summary>

using System.Diagnostics.CodeAnalysis;
using System.Security.Cryptography;
using System.Text;

namespace SenseTimeTracker.Misc
{
	/// <summary>
	/// Implements the password class
	/// </summary>
	public static class Password
	{
		/// <summary>
		/// Encrypts the password
		/// </summary>
		/// <param name="password">Password to be encrypted</param>
		/// <returns>The encrypted password</returns>
		[SuppressMessage("Microsoft.StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", Justification = "MD5 is not hungarian notation")]
		public static string Encrypt(string password)
		{
			MD5 md5Hasher = MD5.Create();
			byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(password));
			StringBuilder hashedPassword = new StringBuilder();
			for (int i = 0; i < data.Length; i++)
			{
				hashedPassword.Append(data[i].ToString("x2"));
			}

			return hashedPassword.ToString();
		}
	}
}
